<template>
<div>
  <p>Text Decrypter</p>
  <form @submit.prevent="decryptText(text, rsaPvtKey);">
    <input type="text" v-model="text" />
    <button>Submit</button>
  </form>
  <pre>{{rsaPvtKey !== undefined ? "has key" : "no key" }}</pre>
  <pre>{{decryptedText}}</pre>
</div>
</template>

<script>
export default {
    name: "TextDecrypter",
    props: ["rsaPvtKey"],
    data() {
        return {
            text: '',
            decryptedText: ''
        }
    },
    methods: {
        decryptText: function(toDecrypt, privatekey) {
            const crypto = require("crypto");
            const constants = require("constants");
            const padding = constants.RSA_PKCS1_PADDING;

            this.decryptedText = crypto.privateDecrypt(
                {
                    key: privatekey,
                    padding: padding,
                },
                new Buffer(toDecrypt, 'base64'));

        },
    },
}
</script>
